package com.ls.book;

import java.util.Random;
import java.util.Scanner;

/**
 * 猜数字小游戏
 */
public class GuessNumGame {

    public static void main(String[] args) {
       Random random = new Random();
       int i = random.nextInt(100);
       Scanner scanner = new Scanner(System.in);
       Integer count = 0;
       Boolean flag = true;
       while (flag){
           System.out.print("请输入你猜的字");
           int num = scanner.nextInt();
           if (num==i){
               System.out.println("你猜对了"+i);
               count++;
               System.out.println("你一共猜了"+count+"次");
               flag = false;
           }else if(num>i){
               System.out.println("你猜大了");
           }else if(num<i){
               System.out.println("你猜小了");
           }
           count++;
       }
    }
}
